using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using FiltronASP.Modules.Abstracts;
using FiltronASP.Models.DAO.Interfaces;
using FiltronASP.Models;
using FiltronASP.Models.DAO.WIX;
using FiltronASP.Models.DAO.Extensions;
using FiltronASP.Models.DAO.Interfaces.WIX;
using FiltronASP.Models.DAO.Filtron;
using FiltronASP.Models.DAO.Interfaces.Filtron;
using FiltronASP.Helpers.Constants;
using FiltronASP.Helpers.Translations;

namespace FiltronASP.Modules
{
    public class mainNewsList : AbstractModule
    {
        private Page currentPage;

        /// <summary>
        /// Klasa odpowiedzialna za generowanie contentu przez modul.
        /// </summary>
        /// <param name="page">biezaca strona</param>
        /// <returns>content</returns>
        public override string GenerateContent(FiltronASP.Models.Page page)
        {
            this.currentPage = page;
            string htmlToReturn = "";
            int languageId = Convert.ToInt32(page.language_id);
         //   htmlToReturn += "<div class=\"rightMenuBoxInner\" style=\"height: 255px;\">";
         // htmlToReturn += "<span class=\"contentRightBoxTitle\">" + translationHelper.getTranslation("_newsTitle", languageId) + "</span>";

            IPageDAO PageDAO = new FiltronASP.Models.DAO.PageDAO();
            IQueryable<Page> pagesCollection = PageDAO.FindByLanguageAndTypeNameAndPublished(7, Constants._newsBoxName, true);
            IVariableValueDAO VariableValueDAO = new Models.DAO.VariableValueDAO();
            ITemplateDAO TemplateDAO = new FiltronASP.Models.DAO.TemplateDAO();
            int newsCounter = 3;

            if (pagesCollection != null)
            {

                foreach (Page singlePage in pagesCollection)
                {
                    if (newsCounter > 0)
                    {
                        VariableValue scope = VariableValueDAO.FindByVariableAndPage(Constants._newsBoxSingleScope, singlePage.page_id, 7);
                        String monthAndYear = scope.variable_value;

                        String splittedMonth = monthAndYear.Split(' ')[0];
                        String splittedYear = monthAndYear.Split(' ')[1];


                       
                        Template templateId = TemplateDAO.FindByLangAndName(Convert.ToInt32(page.language_id), Constants._allImplementation);
                        IQueryable<Page> allImplemetationsPages = PageDAO.FindByLanguageAndTemplateIdAndPublished(Convert.ToInt32(page.language_id), templateId.template_id, true);
                        if (allImplemetationsPages != null)
                        {
                            foreach (Page single in allImplemetationsPages)
                            {
                               htmlToReturn += "  <div class=\"col-lg-12 col-md-4 col-sm-4 col-xs-6 no-padding new-implementation-short\">";
                                htmlToReturn += "     <a href='" + single.page_link + "#" + this.translateMonths(splittedMonth, Convert.ToInt32(page.language_id)) + "%20" + splittedYear + "'>";
                                htmlToReturn += "        <div class=\"col-xs-8 no-padding\">";
                                htmlToReturn += "           <span>" + this.translateMonths(splittedMonth, Convert.ToInt32(page.language_id)) + " " + splittedYear + "</span>";
                                htmlToReturn += "           <p>" + translationHelper.getTranslation("_newProductIntroduction", languageId) + "</p>";
                                htmlToReturn += "       </div>";
                                htmlToReturn += "       <div class=\"col-xs-4 no-padding\">";
                                htmlToReturn += "           <img src=\"" + VirtualPathUtility.ToAbsolute("~/Content/img/button.png") + "\" alt=\"button\">";
                                htmlToReturn += "        </div>";
                                htmlToReturn += "     </a>";
                                htmlToReturn += "   </div>";
                            }
                        }

                      
                        newsCounter--;
                    }
                }
            }


         /*   Template templateIdLast = TemplateDAO.FindByLangAndName(Convert.ToInt32(page.language_id), Constants._allImplementation);
            IQueryable<Page> allImplemetationsPagesLast = PageDAO.FindByLanguageAndTemplateIdAndPublished(Convert.ToInt32(page.language_id), templateIdLast.template_id, true);
            if (allImplemetationsPagesLast != null)
            {
                foreach (Page single in allImplemetationsPagesLast)
                {
                    htmlToReturn += String.Format("<a class=\"allImplementations\" href=\"{0}\">{1}</a>", single.page_link, "<strong>" + translationHelper.getTranslation("_newsAllNews", languageId) + " &raquo;</strong>");
                }
            }*/

          

            return htmlToReturn;
        }

        private string translateMonths(string englishMonth, int languageName)
        {
            if (!englishMonth.Equals(""))
            {
                switch (englishMonth.ToLower())
                {
                    case "january":
                        return translationHelper.getTranslation("_monthJanuary", languageName);
                        break;
                    case "february":
                        return translationHelper.getTranslation("_monthFebruary", languageName);
                        break;
                    case "march":
                        return translationHelper.getTranslation("_monthMarch", languageName);
                        break;
                    case "april":
                        return translationHelper.getTranslation("_monthApril", languageName);
                        break;
                    case "may":
                        return translationHelper.getTranslation("_monthMay", languageName);
                        break;
                    case "june":
                        return translationHelper.getTranslation("_monthJune", languageName);
                        break;
                    case "july":
                        return translationHelper.getTranslation("_monthJuly", languageName);
                        break;
                    case "august":
                        return translationHelper.getTranslation("_monthAugust", languageName);
                        break;
                    case "september":
                        return translationHelper.getTranslation("_monthSeptember", languageName);
                        break;
                    case "october":
                        return translationHelper.getTranslation("_monthOctober", languageName);
                        break;
                    case "november":
                        return translationHelper.getTranslation("_monthNovember", languageName);
                        break;
                    case "december":
                        return translationHelper.getTranslation("_monthDecember", languageName);
                        break;
                }
            }
            return String.Empty;
        }

    }
}
